<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>个人资料</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../../../lib/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="../../../css/public.css" media="all" />
	<style type="text/css">

	</style>
</head>
<body>
	<div class="layuimini-container">
	    <div class="layuimini-main">
			<!--查询代码  开始-->
			<fieldset class="table-search-fieldset">
			    <legend>搜索信息</legend>
			    <div style="margin: 10px 10px 10px 10px">
			        <form class="layui-form layui-form-pane" action="" id="searchFrm">
						<div class="layui-form-item">
						    <div class="layui-inline">
						        <label class="layui-form-label">用户名称</label>
						        <div class="layui-input-inline">
						            <input type="text" name="userName" autocomplete="off" class="layui-input">
						        </div>
						    </div>
						    <div class="layui-inline">
						        <label class="layui-form-label">电话号码</label>
						        <div class="layui-input-inline">
						            <input type="text" name="phoneNum" autocomplete="off" class="layui-input">
						        </div>
						    </div>
						    <div class="layui-inline">
						        <button type="button" class="layui-btn" lay-submit  lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
						        <button type="button" class="layui-btn layui-btn-warm" onclick="javascript:$('#searchFrm')[0].reset()" ><i class="layui-icon">&#xe669;</i> 清 空</button>
						    </div>
						</div>
					</form>
				</div>
			</fieldset>

			
			    <table class="layui-hide" id="userTableId" lay-filter="userTableFilter"></table>
				<div id="test1"></div>
				
				<!-- <table class="layui-hide" id="deptTableId" lay-filter="deptTableFilter"></table> -->
			
			    <script type="text/html" id="userTableTemplet">
			        <a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
			        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
					<a class="layui-btn layui-btn-xs layui-btn-warm data-count-edit" lay-event="block">拉黑</a>
			    </script>
			    <!--数据表格  结束-->
				<!--添加和修改弹出层代码  开始-->
				<div id="addAndUpdateDiv" style="display: none; padding: 0.3125rem;" >
					<form id="dataFrm" lay-filter="dataFrm" method="post" class="layui-form layui-form-pane">
						<div class="layui-form-item">
							<label class="layui-form-label">用户名</label>
							<div class="layui-input-block">
								<input type="hidden" name="userId" />
								<input type="text" name="userName" lay-verify="userName" autocomplete="off" placeholder="请输入用户名称" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">密码</label>
							<div class="layui-input-block">
								<input type="text" name="pwd" lay-verify="pwd" autocomplete="off" placeholder="" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">电话号码</label>
							<div class="layui-input-block">
								<input type="text" name="phoneNum" lay-verify="phoneNum" autocomplete="off" placeholder="请输入电话号码" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-input-block" style="text-align: center;">
								 <button type="button" class="layui-btn" lay-submit  lay-filter="doSubmit"><i class="layui-icon">&#xe608;</i> 保存</button>
								 <button type="button" class="layui-btn layui-btn-warm" id="doClose" ><i class="layui-icon">&#x1007;</i> 关 闭</button>
							</div>
						</div>
					</form>
					
					
				</div>
		</div>		
	</div>	
</body>



<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../../lib/layui/layui.js" charset="utf-8"></script>
<script src="../../../js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script src="../../../lib/jquery-3.4.1/jquery.cookie.min.js" charset="utf-8"></script>
<script type="text/javascript" src="../../../lib/common/common.js"></script>

<script type="text/javascript">
	
	layui.use(['form','upload','layer','table'],function(){
		var $ = layui.jquery,
		    form = layui.form,
		    table = layui.table,
		    layer=layui.layer;


        //table渲染数据表格
       var tableIns = table.render({
            elem: '#userTableId',
            url: api+'sys/user/loadAllUser',
            toolbar: '#userTableToolbar',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox",  fixed: "left",align:"center"},
                {field: 'userId',  title: 'ID', align:"center"},
                {field: 'userName',  title: '角色名称'},
                {field: 'createTime',  title: '发布时间',align:"center"},
                {field: 'phoneNum',  title: '电话号码',align:"center"},
				{field: 'status',title: '状态',align:"center",templet:function(d){
					if(d.status==0){return '<span style="color: #c00;">禁用</span>'}
					if(d.status==1){return '<span style="color: green;">可用</span>'}
				}},
                {title: '操作',  templet: '#userTableTemplet', fixed: "right", align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var params=$("#searchFrm").serialize();
            table.reload('userTableId', {
                page: {
                    curr: 1
                }
                , url: api+'sys/user/loadAllUser?'+params
            }, 'data');
            return false;
        });
			table.on('tool(userTableFilter)', function (obj) {
			    var data = obj.data;
			    if (obj.event === 'edit') {
					openUpdateLayer(obj);
			    } else if (obj.event === 'delete') {
			       deleteDataById(obj);
			    }else if(obj.event==='block'){
					// alert("设置权限");
					// console.log("设置");
				    blockDataById(obj);
				}
			});
			
			var mainIndex;
			//打开修改页面
			function openUpdateLayer(data){
				 mainIndex = layer.open({
				    title: '编辑角色',
				    type: 1,
				    shade: 0.2,
				    maxmin:true,
				    shadeClose: true,
				    area: ['800', '600'],
				    content: $("#addAndUpdateDiv"),
					success:function(){
						 for(let key  in data.data){
						        console.log(key + '---' + data.data[key])
						  }
						// console.log("data:"+data.data);
						url=api+"sys/user/updateuser";
						form.val("dataFrm",data.data);//填充表单
						// $("#dataFrm")[0].reset();//重置表单
						// editor.txt.html(data.content);//设置富文本的初始化内容
					}
				});
				$(window).on("resize", function () {
				    layer.full(mainIndex);
				});
			}
			
			//提交数据
			form.on("submit(doSubmit)",function(data){
			    var params= $("#dataFrm").serialize();
				// var content=editor.txt.html();
				//params+="&content="+content;
				//alert(params);
				$.post(url,{userId:data.field.userId,phoneNum:data.field.phoneNum,userName:data.field.userName,password:data.field.pwd,},function(res){
					console.log(res);
					layer.msg(res.msg);
					if(res.code==1){
						tableIns.reload();
					}
					layer.close(mainIndex);
				});
				
				return false;
			});
			//关闭窗口
			$("#doClose").click(function(){
				layer.close(mainIndex);
			})
			//根据ID删除
			function deleteDataById(obj){
				 var data = obj.data;
				layer.confirm('真的删除【'+data.userName+'】这行数据么', function (index) {
					$.post(api+"sys/user/deleteUser",{id:data.userId},function(res){
						if(res.code==1){
							// obj.del();
						} 
						layer.msg(res.msg);
						tableIns.reload();
						layer.close(index);
					})
				});
			}
			//根据ID拉黑用户
			function blockDataById(obj){
				 var data = obj.data;
				layer.confirm('真的拉黑【'+data.userName+'】吗？', function (index) {
					$.post(api+"sys/user/blockUser",{id:data.userId},function(res){
						if(res.code==1){
							// obj.del();
						} 
						layer.msg(res.msg);
						tableIns.reload();
						layer.close(index);
					})
				});
			}

	});
	
</script>
</html>